package com.zw.yzk.kabu.im;

import android.net.Uri;

import com.zw.yzk.kabu.data.network.ServiceGenerator;
import com.zw.yzk.kabu.data.network.entity.ImInfoEntity;
import com.zw.yzk.kabu.data.network.service.ImInfoService;


import io.rong.imkit.RongIM;
import io.rong.imlib.model.UserInfo;
import retrofit2.Call;
import retrofit2.Response;


/**
 * Created by wei on 2016/10/13.
 */
public class ImUserUtil {

    /**
     * 设置用户信息
     */
    public static void setUserInfo() {
        RongIM.setUserInfoProvider(new RongIM.UserInfoProvider() {
            @Override
            public UserInfo getUserInfo(String userId) {
                Call<ImInfoEntity> call = ServiceGenerator.createPureService(ImInfoService.class).getImInfo1(userId);
                try {
                    Response<ImInfoEntity> response = call.execute();
                    ImInfoEntity entity = response.body();
                    if (entity.result != null) {
                        String name = entity.result.nickName;
                        String img = entity.result.img;
                        UserInfo userInfo = new UserInfo(userId, name, Uri.parse(img));
                        RongIM.getInstance().refreshUserInfoCache(userInfo);
                        return userInfo;
                    }
                } catch (Exception e) {
                    return new UserInfo(userId, "", null);
                }
                return new UserInfo(userId, "", null);
            }
        }, true);
    }
}
